#ifndef GAMEDIALOGITEM_H
#define GAMEDIALOGITEM_H

#include <QPainter>
#include <QGraphicsObject>
#include "gs.h"
using namespace gs;

namespace gs
{
class GameDialogItem : public QGraphicsObject
{
public:
    GameDialogItem(GameDialog*);
    GameDialog* getDialog(){return _dialog;}
protected:
    GameDialog* _dialog;
};

class GameDialogButton : public GameDialogItem
{
    Q_OBJECT
public:
    GameDialogButton(GameDialog*);
    QRectF boundingRect() const;
    void setLabel(QString);
    void setPixmap(QPixmap);
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    const static int WIDTH = 80;
    const static int HEIGHT = 30;
protected:
    QString _label;
    QPixmap _bg;
signals:
    void pressed();
};

class GameDialogTaoButton : public GameDialogButton
{
    Q_OBJECT
public:
    GameDialogTaoButton(GameDialog*, GSColor);
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    GSColor _c;
};

class GameDialogHeadButton : public GameDialogItem
{
    Q_OBJECT
public:
    GameDialogHeadButton(GameDialog*, GSColor);
    Player* getSelectedPlayer() { return choosenPlayer; }
    const static int headWidth = 100;
    const static int headHeight = 140;
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QRectF boundingRect() const;
    GSColor _c;
    QPixmap _headPix;
    Player* choosenPlayer;
signals:
    void click(GameDialogHeadButton*);
};

class GameDialogDice : public GameDialogItem
{
    Q_OBJECT
    Q_PROPERTY(int side READ getSide WRITE setSide)
public:
    GameDialogDice(GameDialog*);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    void setSide(int s){side = s;}
    int getSide(){return side;}
    GSColor getSideColor();
    void stop();
    bool isActive();
protected:
    QList<QPixmap> _colors;
    int side;
    QTimer* rAnim;
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
public slots:
    void roll();
};

class DialogTips : public GameDialogItem
{
    Q_OBJECT
public:
    DialogTips(GameDialog*, QString);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    const static int WIDTH = 1024;
    const static int HEIGHT = 30;
protected:
    QString tipName;
};

class TaoItemButton : public GameDialogItem
{
    Q_OBJECT
public:
    TaoItemButton(GameDialog*, gs::GSColor, Player* p);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    const static int WIDTH = 44;
    const static int HEIGHT = 44;
protected:
    void setItemPix(gs::GSColor c);
    void setPlayerTao(gs::GSColor c);
    GSColor _color;
    Player* _pl;
    QPixmap _taoPix;
    int remainNum;
    QFont _font;
};
}
#endif // GAMEDIALOGITEM_H
